package com.xitang.customer.controller;

import com.xitang.common.bean.BizCategory;
import com.xitang.common.dto.CategoryQueryReq;
import com.xitang.common.dto.PageQueryRsp;
import com.xitang.common.dto.ResultVO;
import com.xitang.common.service.ICategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "分类接口列表-客户")
@RestController
public class CustomerCategoryController extends BaseCustomerController {
    @Autowired
    private ICategoryService categoryService;

    @ApiOperation(value = "获取分类列表信息", notes = "获取分类列表信息")
    @GetMapping("/category")
    public ResultVO<List<BizCategory>> categoryList(@RequestParam(name = "page", required = false) Integer page,
                                                    @RequestParam(name = "limit", required = false) Integer limit,
                                                    @RequestParam(name = "categoryCode", required = false) String categoryCode,
                                                    @RequestParam(name = "categoryName", required = false) String categoryName) {
        CategoryQueryReq queryReq = CategoryQueryReq.builder().pageNo(page).pageSize(limit).categoryCode(categoryCode)
                .categoryName(categoryName).build();
        PageQueryRsp<BizCategory> pageQueryRsp = categoryService.getCategoryList(queryReq);
        return ResultVO.success(pageQueryRsp.getRecords(), pageQueryRsp.getTotal());
    }

    @ApiOperation(value = "获取分类详细信息", notes = "根据分类编码获取分类详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "categoryCode", value = "分类编码", dataType = "String")
    })
    @GetMapping("/category/{categoryCode}")
    public ResultVO<BizCategory> productDetail(@PathVariable("categoryCode") String categoryCode) {
        return ResultVO.success(categoryService.getCategoryDetail(categoryCode));
    }
}
